package entity

import (
	"strconv"
	"time"

	"shqsoft.cn/pasnj/base"
	"shqsoft.cn/pasnj/bi/cube"
)

type CM_GUAR_INFO_SUM_M struct {
	ID     int        `gorm:"AUTO_INCREMENT;primary_key;column:JLID"`
	Sjrq   *time.Time `gorm:"column:数据日期;type:date;"`
	Khmc   string     `gorm:"column:客户名称;"`
	Bhje   *float64   `gorm:"column:保函金额;"`
	Dqye   *float64   `gorm:"column:当前余额;"`
	Bzjje  *float64   `gorm:"column:保证金金额;"`
	Sxfje  *float64   `gorm:"column:手续费金额;"`
	Zzjgdm string     `gorm:"column:组织机构代码"`
	Ssjg   string     `gorm:"column:所属机构"`
	Klrq   *time.Time `gorm:"column:开立日期;type:date;"`
	Dqrq   *time.Time `gorm:"column:到期日期;type:date;"`
	Sxrq   *time.Time `gorm:"column:生效日期;type:date;"`
	Hbdm   string     `gorm:"column:货币代码"`
	Hszl   string     `gorm:"column:人民币保函核算种类代码"`
	Bhzl   string     `gorm:"column:保函种类代码"`
	Kmh    string     `gorm:"column:科目号;"`
	Km     string     `gorm:"column:科目;"`
	CUID   int        `gorm:"column:CUID"`
	YG1    string     `gorm:"-"`
	ZB1    *float64   `gorm:"-"`
	YG2    string     `gorm:"-"`
	ZB2    *float64   `gorm:"-"`
	YG3    string     `gorm:"-"`
	ZB3    *float64   `gorm:"-"`
	YG4    string     `gorm:"-"`
	ZB4    *float64   `gorm:"-"`
	YG5    string     `gorm:"-"`
	ZB5    *float64   `gorm:"-"`
}

//TableName 卡号表名
func (CM_GUAR_INFO_SUM_M) TableName() string {
	return "V_CM_GUAR_INFO_SUM_M"

}

func (c *CM_GUAR_INFO_SUM_M) AfterFind() (err error) {
	var share *cube.Share
	share, err = cube.GetShare("comp_qtzb_divi")
	if err != nil {
		return
	}
	var diviMap map[string]float64
	diviMap, err = share.GetDivision("2:" + strconv.Itoa(c.ID))
	if err != nil {
		return
	}
	i := 0
	if diviMap == nil || len(diviMap) == 0 {
		share, err = cube.GetShare("comp_clie_divi")
		if err != nil {
			return
		}
		diviMap, err = share.GetDivision(strconv.Itoa(c.CUID))
		if err != nil {
			return
		}
	}
	for k, v := range diviMap {
		val := v
		i++
		switch i {
		case 1:
			c.YG1 = k
			c.ZB1 = &val
		case 2:
			c.YG2 = k
			c.ZB2 = &val
		case 3:
			c.YG3 = k
			c.ZB3 = &val
		case 4:
			c.YG4 = k
			c.ZB4 = &val
		case 5:
			c.YG5 = k
			c.ZB5 = &val
		default:
			break
		}
	}
	return
}

//V_Divi_CxEF 保函
func CM_GUAR_INFO_SUM_MEF() base.EntityFunc {
	return func() interface{} {
		entity := CM_GUAR_INFO_SUM_M{}
		return &entity
	}
}

//ZTXMCMXESF 保函
func CM_GUAR_INFO_SUM_MESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []CM_GUAR_INFO_SUM_M
		return &entities
	}
}
func init() {
	dao := base.NewDefaultDao(CM_GUAR_INFO_SUM_MEF(), CM_GUAR_INFO_SUM_MESF(), nil)
	filter := base.DefaultFilter{
		FilterColName: "CUID",
		TableName:     "T_COMP_CLIE_YGFC",
		EmidColName:   "emid",
		AcidColName:   "CUID",
		WhereCause:    "DTID=dbo.GetDateToInt(dbo.GetCurSysDate())",
	}
	dao.Fileter = &filter
	base.DaoPoolObj.Put("CM_GUAR_INFO_SUM_M", dao)
}
